$(function() {
	/* 单击右边列表的按钮，改变其模态框的按钮状态 */
	$("#addVarieties").click(
			function() {
				publicstatus("add");
				attr(false);
				document.getElementById("firstVarietyForm").reset();

				for ( var i = 13; i <= 17; i++) {
					$("#firstVarietyForm table tr:eq(" + i + ") input").attr(
							"readonly", true);
					$("#firstVarietyForm table tr:eq(" + i + ") input").attr(
							"disabled", true);
					$("#firstVarietyForm table tr:eq(" + i + ") select").attr(
							"disabled", true);
				}
			});
	$("#updateVarieties").click(function() {
		publicstatus("update");
		attr(false);
	});
	$("#copyadd").click(function() {
		publicstatus("copyadd");
		attr(false);
	});

	$("#salesman").click(function() {
		signpublic("#businesssign", "salesman");
		$("#retreat").css("display", "inline-block");
		attr(true);
	});

	$("#busdepar").click(function() {
		signpublic("#businessdepsign", "busdepar");
		$("#retreat").css("display", "inline-block");
		attr(true);
	});

	$("#quamandepar").click(function() {
		signpublic("#qcdepsignsign", "quamandepar");
		$("#retreat").css("display", "inline-block");
		attr(true);
	});

	$("#qualityleader").click(function() {
		signpublic("#qcpeosignsign", "qualityleader");
		$("#retreat").css("display", "inline-block");
		attr(true);
	});

	$("#commyInfo").click(function() {
		buttonpublic("commyInfo");
		$("#changegoods").css("display", "inline-block");
		attr(true);
	});
});

function aucc() {
	$(".special>.btn").css("display", "none");
	$("#save").css("display", "inline-block");
	$("#close").css("display", "inline-block");
}

function publicstatus(str) {
	buttonpublic(str);
	$("#save").css("display", "inline-block");
}

function signpublic(str, sign) {
	buttonpublic(sign);
	$("#retreat").css("display", "inline-block");
	$(str).css("display", "inline-block");
}

function buttonpublic(str) {
	$("#isAddOrUpdate").val(str);
	$(".special>.btn").css("display", "none");
	$("#close").css("display", "inline-block");
}

function attr(obj) {
	$("#firstVarietyForm input").attr("readonly", obj);
	$("#firstVarietyForm input").attr("disabled", obj);
	$("#firstVarietyForm select").attr("disabled", obj);
	$("#firstVarietyForm textarea").attr("readonly", obj);
	$("#choose").attr("data-target", "#setting");
}

function switchflush() {
	var str = $("#differentiate").val();
	switch (str) {
	case "basicinfo": // 基本资料 
		getvarietyList("../../firstvariety/getVarietyList");
		break;
	case "salesman": // 业务员
		getvarietyList("../../firstvariety/getSalesmanNotAudit");
		break;
	case "busdepar": // 业务部
		getvarietyList("../../firstvariety/getDepartmentNotaudit");
		break;
	case "quamandepar": // 质量管理部审核
		getvarietyList("../../firstvariety/getQualityControlNotaudit");
		break;
	case "qualityleader": // 质量负责人审批
		getvarietyList("../../firstvariety/getQqualityDirecterNotaudit");
		break;
	case "commyInfo": // 转为商品资料
		getvarietyList("../../firstvariety/getPendingCommodity");
		break;
	default: 
		alert("没有找到对应的选项，无刷新失败！位置-->changebutton.js");
		break;
	}
}